/*
  this file contains functions related to obtaining and displaying
  workspace and dashboard data, most of these functions are assigned
  to much easier to use objects in the Layouts file
*/

// gets workspace data
function getWorkspace(id) {

  if ((id=="") || (id==null) || (id==undefined)) { // default to dashboard if something weird / nothing supplied
  
    id = 0;
  
  }

  if (huddle.isAuth()) { // check authentication first

    if (id == 0) {

      json.getData("workspaces", allworkspaces.display);
      
    } else {
    
      json.getData("workspace",workspace.display, id);
      
    }
    
  } else {
  
    page.switchContent("login",null);
    
  }

}

// display the dashboard
function displayWorkspaces(data) {

  workspaces = data.Data;
  
  drag.remove("huddle");
  
  if (workspaces.length == 0) {
  
    $("#huddle>div>div").append("You don't have any workspaces");
  
  } else {
  
    makeTable(workspaces);
    
    for (x in workspaces) {
    
      dropdown.push(workspaces[x].Title, workspaces[x].Id); // populate the dropdown when loaded
    
    }
    
    dropdown.get(); // display the dropdown
    
  }

}

// display data in a single workspace
function displayWorkspace(data) {

  items = data.Data;
  
  //drag.remove("huddle");
  
  if (items.length == 0) {
  
    $("#huddle>div>div").append("This workspace is empty");
  
  } else {
   
    makeTable(items); // make the grid of items
  
  }

}